// packageA/pages/performs/performssession/performssession.js
var common = require("../../../public.js");
Page({

    /**
     * 页面的初始数据
     */
    data: {
        totalMoney:0.00,
        dateDisplayList:[],
        activeindex:-1,
        activeindexs:-1,
        pirce_box:'',
        chang_time:'',
        ticketCount: 1
    },
    selectDate(e){
        let {
            index,item
          } = e.currentTarget.dataset
          console.log(item)
        this.setData({
            activeindex:index,
            chang_time:item
          
        })
    },
    selectprice(e){
      let {
        index,item
      } = e.currentTarget.dataset
      console.log(item)
    this.setData({
        activeindexs:index,
        pirce_box:item,
        totalMoney: this.data.ticketCount * item.ticketPrice  * 100 // 单位分
    })
    },
    onCountChange(e) {
        console.log(e.detail)
        if (this.data.pirce_box && this.data.chang_time) {
          const num = e.detail
        
          this.setData({
            ticketCount: num,
            totalMoney: num * this.data.pirce_box.ticketPrice  * 100 // 单位分
          })
        } else {
          this.setData({
            ticketCount: 1
          })
          common.showToast('请先选择日期及价格')
        }
      },
    /**
     * 生命周期函数--监听页面加载
     */
    submitOrder(){
     wx.navigateTo({
       url: '/packageA/pages/performs/performOrder/performOrder?storeId=' + this.data.storeId +
       '&ticketName=' + this.data.ticketName +
       '&storeName=' + this.data.storeName +
       '&ticketPrice=' +  this.data.pirce_box.ticketPrice +
       '&ticketNum=' + this.data.ticketCount +
       '&date_box=' + this.data.chang_time.performTimeDisplay+
       '&holdingAddress=' + this.data.holdingAddress +
       '&totalMoney=' + this.data.totalMoney + 
       '&ticketTimeId=' + this.data.chang_time.id +   //时间id  
       '&ticketPriceId=' + this.data.pirce_box.id +   //金钱id
       '&storePerformId=' + this.data.id + //没票
       '&performTimeDisplay=' + this.data.chang_time.performTimeDisplay+  //没票
       '&performTime=' +this.data.chang_time.performTime,

     })

    },
    onLoad: function (options) {
        console.log(options)
        const title = options.storeName + '-' + options.ticketName
        wx.setNavigationBarTitle({ title })
        this.setData({
         id : options.storePerformId ? options.storePerformId :'',
         storeId:options.storeId ?options.storeId :'',
         ticketName: options.ticketName ?options.ticketName :'',
         storeName: options.storeName ?options.storeName :'',
         holdingAddress: options.holdingAddress ?options.holdingAddress :'',
        },()=>{
          // 调取演艺演出的场次
          this.chang()
          this.price_fn()
        })
      
    },

    chang(){
        var that = this
        var tempJson ={
            storePerformId:27
        }
        common.post('/storePerform/getStorePerformNums', tempJson, res => {
             console.log(res)
             that.setData({
                dateDisplayList:res.data
             })
         })
    },
    price_fn(){
      var that = this
      var tempJson ={
          storePerformId:this.data.id
      }
      common.post('/storePerform/getStorePerformTicket', tempJson, res => {
           console.log(res)
           that.setData({
              priceList:res.data
           })
       })
    },
    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function () {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function () {

    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function () {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function () {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function () {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function () {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function () {

    }
})